﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SimpleRest.Core.Routing.Handlers;

namespace SimpleRest.Core.Extensions.Handlers
{
    public class CorrelationMessageHandler : IHttpMessageHandler
    {
        public const string CorrelationIdKey = "x-correlation-id";
        public ExecuteResponseHandler Execute(MessageHandlerContext requestContext)
        {
            var corrrelationIdHeader = new Header(CorrelationIdKey, Guid.NewGuid().ToString("N"));

            requestContext.Request.Headers.Add(corrrelationIdHeader);
            return (response) =>
            {
                response.ResponseHeaders.Add(corrrelationIdHeader);
            };
        }
    }
}
